/**
 * 
 */
package com.istart.tika.content;

import java.io.File;
import java.io.FileInputStream;

import org.apache.tika.metadata.Metadata;
import org.apache.tika.parser.AutoDetectParser;
import org.apache.tika.parser.ParseContext;
import org.apache.tika.parser.Parser;
import org.apache.tika.sax.BodyContentHandler;

/**
 * 使用解析器接口来提取内容
 * @author 谢进军
 */
public class ParserExtraction {
	private final static String filepath = "src/main/resources/com/istart/tika/tika.txt";
	
	public static void main(String[] args) throws Exception {
		File file = new File(filepath);
		
		Parser parser = new AutoDetectParser();
		BodyContentHandler handler = new BodyContentHandler();
		Metadata metadata = new Metadata();
		FileInputStream inputstream = new FileInputStream(file);
		ParseContext context = new ParseContext();
		parser.parse(inputstream, handler, metadata, context);
		System.out.println("File content : " + handler.toString());
	}
}
